# webpack4 环境搭建
# 前言
由于demos/project 前端渲染是通过react.js渲染的,这就需要webpack4 对react.js及其相关JSX,ES6/7代码进行编译和混淆压缩。
# webpack4
# 安装和文档
# 配置webpack4编译react.js + less + sass + antd 环境
# 文件目录
└── static # 项目静态文件目录
├── build
│ ├── webpack.base.config.js # 基础编译脚本
│ ├── webpack.dev.config.js # 开发环境编译脚本
│ └── webpack.prod.config.js # 生产环境编译脚本
├── output # 编译后输出目录
│ ├── asset
│ ├── dist
│ └── upload
└── src # 待编译的ES6/7、JSX源代码
├── api
├── apps
├── components
├── pages
├── texts
└── utils
@前端进阶之旅: 代码已经复制到剪贴板
# webpack4 编译基础配置
# babel@7 配置
const babelConfig = {
presets: [
'@babel/env',
// [
// '@babel/env',
// {
// targets: {
// edge: '17',
// firefox: '60',
// chrome: '67',
// safari: '11.1'
// },
// useBuiltIns: 'usage'
// }
// ],
'@babel/preset-react'
],
'plugins': [
[
'import',
{ 'libraryName': 'antd', 'libraryDirectory': 'lib' },
'ant'
],
[
'import',
{ 'libraryName': 'antd-mobile', 'libraryDirectory': 'lib' },
'antd-mobile'
],
'@babel/plugin-proposal-class-properties'
]
};
module.exports = babelConfig;
